import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== $Lazy
const Tips 			= $Lazy.load(()=>import('#tp/tips'))
const message 		= $Lazy.file(()=>import('@antd/message'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		formData : [
			{ label: '姓名',		name: 'user_name',	full:true,		disabled:true,	p:' ' },
			{ label: '用户名',		name: 'phone',		full:true,		disabled:true,	p:' ' },
			{ label: '密码',		name: 'password',	full:true,		value:'',		type:'password',	onEnter:()=>this.onOk() },
		],
		
	}
	user = {}
	
	open = () => {
		this.user = $fn.getUser()
		const { empl_name, real_name } = this.user
		this.modal.open({formRef:this.formRef})
		localStorage.setItem('lockScreen', 1)
		this.formRef.setValue({'phone': empl_name,'user_name':real_name,'password':''})
	}
	close = () => {
		this.modal.close()
		localStorage.setItem('lockScreen', 0)
	}
	onOk = () => {
		const param = this.formRef.getValue(['password'])
		$http.submit(this,'employee/getuserrealname',{param: {phone:this.user.empl_name,...param}}).then((data)=>{
			if(data.empl_name === this.user.empl_name){
				this.close()
			}else{
				message.then(f=>f.error('密码错误，请重新输入'))
			}
		})
	}
	onCancel = () => {
		$fn.go('/login')
		window.lockTimer && clearTimeout(window.lockTimer)
		localStorage.setItem('lockScreen', 0)
	}
		
	render(){
		return(
			FormModal.call(this,{title:'提示', labelWidth:'s4', width:600,
				closable:false, noText:'重新登录',onOk:this.onOk,onCancel:this.onCancel,
				prefix: (<Tips text='由于您长时间未操作, 请重新输入密码' className = 'mb5' />)
			})
		)			
	}
}

export default Index